<template>
    <page-wrap>
        <div class="container">

            <div class="page-title">兑换券信息</div>
            <div class="info-box">
                <div class="title-row">{{ ticketInfo.ticketName }}</div>
                <div class="info-row">
                    <span class="label">有效日期：</span><span class="value">{{ ticketInfo.startData }} - {{ ticketInfo.endData
                    }}</span>
                </div>
                <div class="info-row">
                    <span class="label">可使用时段：</span><span class="value">不限制</span>
                </div>
                <div class="info-row">
                    <span class="label">使用条件：</span>

                    <span class="value" v-if="ticketInfo.useCondition == 1">每个会员可以使用{{
                        ticketInfo.memberUseNum }}张</span>
                    <span class="value" v-else-if="ticketInfo.useCondition == 2">每个桌台可以使用{{
                        ticketInfo.roomUseNum }}张</span>
                    <span class="value" v-else-if="ticketInfo.useCondition == 0">无限制</span>
                </div>
                <div class="info-row">
                    <span class="label">商品信息：</span><span class="value">{{ ticketInfo.goodsName }} * {{
                        ticketInfo.goodsCount
                    }}</span>
                </div>
            </div>
            <div class="color-999999 font-size-14">是否确认核销该券，核销后不能撤销！ </div>

        </div>

        <div class="footer-box">
            <button class="cancel" @click="handleCancel">取消</button>
            <button class="submit" @click="handleSubmit">确认</button>
        </div>
    </page-wrap>
</template>

<script setup >
import Api from '@/api'
import { showToast } from 'vant';

const router = useRouter()
const route = useRoute()
const code = route.query.code
const consumeCode = route.query.consumeCode
const activeType = route.query.activeType
console.log(activeType,'activeType')
const ticketInfo = ref({})
const getTicketInfo = (params) => {
    const data = {
        memberTicketCode: code
    }
    Api.Common.AppObjProcess.Do({ "functionName": "GetGoodsTicket", "contentData": data })
        .then(res => {
            console.log('获取券信息 res :>> ', res);
            ticketInfo.value = res
        })
        .catch(() => {

        })
}

onMounted(() => {
    getTicketInfo()
})

const handleCancel = (params) => {
    router.back()
}

const handleSubmit = (params) => {
         // 抖音核销卷  
        if(activeType == 1) {
                const data = {
                        tiktopCode: code,
                        consumeCode: consumeCode,
                        memberCarCode: ticketInfo.value.memberCarCode
                    }

            Api.Common.AppObjProcess.Do({ "functionName": "WriteOffTicket", "contentData": data })
        .then(res => {
            console.log('使用券 res :>> ', res);
            showToast('使用成功')
            router.push({
                path: '/open'
            })
        })
        .catch(() => {

        })
        } else {
            const data = {
        memberTicketCode: code,
        consumeCode: consumeCode,
        memberCarCode: ticketInfo.value.memberCarCode,
             }

            Api.Common.AppObjProcess.Do({ "functionName": "UseGoodsTicket", "contentData": data })
        .then(res => {
            console.log('使用券 res :>> ', res);
            showToast('使用成功')
            router.push({
                path: '/open'
            })
        })
        .catch(() => {

        })
        }
}

</script>

<style scoped lang="scss">
.container {
    padding: 20px 13px;
    font-family: PingFang SC;
    color: #FFFFFF;
    padding-bottom: 85px;

    .page-title {
        font-family: PingFang SC;
        font-weight: bold;
        font-size: 16px;
        color: #FFFFFF;
        margin-bottom: 20px;
    }

    .info-box {
        background: #28282E;
        border-radius: 8px;
        padding: 12px 20px 18px 20px;
        margin-bottom: 14px;

        .title-row {
            font-weight: bold;
        }

        .info-row {
            padding-top: 12px;
            font-weight: 500;
            font-size: 14px;

            .label {
                color: #CCCCCC;
            }

            // .value {}
        }
    }


}

.footer-box {
    position: absolute;
    bottom: 0px;
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 20px 50px 20px;

    background: #17171A;

    .cancel {
        width: 120px;
        height: 40px;
        border-radius: 20px;
        border: 1px solid #CCBEA3;
        font-family: PingFang SC;
        font-weight: 500;
        font-size: 18px;
        color: #CCBEA3;
        background: #17171A;
    }

    .submit {
        width: 120px;
        height: 40px;
        background: linear-gradient(0deg, #CCA67A, #FFF4D9);
        border-radius: 20px;
        font-family: PingFang SC;
        font-weight: 500;
        font-size: 18px;
        color: #260C04;
    }
}

.color-999999 {
    color: #999999;
}

.font-size-14 {
    font-size: 14px;
}
</style>
